package com.yonyou.pmclouds.repeatwork.process;

import com.yonyou.pmclouds.basecom.billstatus.BillStatusConst;
import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.repeatwork.entity.RepeatWorkVO;
import com.yonyou.pmclouds.repeatwork.service.rmiitf.IRepeatWorkQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 复工单防止重复提交判断
 */
@Component
public class RepeatWorkCommitDupProcessor implements SingleProcessor<RepeatWorkVO> {

    @Autowired
    private IRepeatWorkQuery repeatWorkQuery;

    @Override
    public void process(RepeatWorkVO vo, RepeatWorkVO orig) throws BusinessException {
        //查询当前复工的项目是否已经存在自由态，审批中，提交或者驳回的复工单。
        String pk_project = vo.getPkProject();
        int[] status = {BillStatusConst.COMMON_FREE_STATUS,BillStatusConst.COMMON_COMMIT_STATUS,BillStatusConst.COMMON_APPROVING_STATUS,BillStatusConst.COMMON_REJECT_STATUS};
        RepeatWorkVO[] vos = repeatWorkQuery.queryByStatus(pk_project,status);
        if (vos != null && vos.length>0){
            throw new BusinessException("该项目已复工, 请不要重复发起复工");
        }
    }
}
